<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <script type="text/javascript">
    // 早期自定义字符串格式
    // 后来又XML标准格式，但是有缺点，所以有了JSON
    // JSON 详解
    // JavaScript Object Notation （javascript对象标记语言）
    // JSON是描述字符串的一种格式，具体规则如下
    /*
      - 数据结构为键值对 uname: 'lisi'
      - key 必须是使用英文的双引号包裹的字符串 "uname":"lisi"
      - 字符串类型的值必须使用双引号包裹 "uname":"lisi"
      - JSON 中不能写注释
      - JSON 的最外层必须是对象或数组格式
      - 不能使用 undefined 或函数作为 JSON 的值
      - value 的数据类型可以是数字、字符串、布尔值、null、数组、对象6种类型
     */
    

    // 如下内容是覆盖JOSN规则的字符串
    var str = '{"status":200,"msg":"获取图书列表成功","data":[{"id":1,"bookname":"西游记","author":"吴承恩","publisher":"北京图书出版社"},{"id":2,"bookname":"红楼梦","author":"曹雪芹","publisher":"上海图书出版社"},{"id":3,"bookname":"三国演义","author":"罗贯中","publisher":"北京图书出版社"},{"id":5,"bookname":"抗击疫情自传","author":"菲斯在-周末人","publisher":"广西出版社"},{"id":6,"bookname":"一本书","author":"李四","publisher":"abc"},{"id":7,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":8,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":9,"bookname":"三国演义","author":"罗贯中","publisher":"北京图书出版社"},{"id":10,"bookname":"hello","author":"abc","publisher":"haha"},{"id":11,"bookname":"谁日了我的狗","author":"是你吗","publisher":"时你们吗?"},{"id":12,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":13,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":14,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":15,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":16,"bookname":"百年孤独","author":"尼古拉斯·赵四","publisher":"中华出版社"},{"id":17,"bookname":"百年孤独","author":"尼古拉斯·赵四","publisher":"中华出版社"},{"id":18,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":19,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":20,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":21,"bookname":"hello","author":"abc","publisher":"hahaha"},{"id":22,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":23,"bookname":"hello","author":"abc","publisher":"n11111"},{"id":24,"bookname":"百年孤独","author":"尼古拉斯·赵四","publisher":"中华出版社"},{"id":25,"bookname":"百年孤独","author":"尼古拉斯·赵四","publisher":"中华出版社"},{"id":26,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":27,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":28,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":29,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":30,"bookname":"hello","author":"abc","publisher":"nihao"},{"id":31,"bookname":"hello","author":"abc","publisher":"你好"},{"id":32,"bookname":"谁日了我的狗","author":"是你吗","publisher":"是你们吗?"}]}'
    
    // 如果希望获取JSON字符串中的具体的属性值，需要转换成js对象
    // var obj = JSON.parse(str)
    // console.log(obj.data)
    // ------------------------------------------
    // 如果有一个js对象，也可以转换成JSON字符串
    var obj = {
      uname: 'lisi',
      age: 12,
      gender: 'male'
    }
    var userStr = JSON.stringify(obj)
    console.log(userStr)
    console.log(typeof userStr)
  
  </script>
</body>
</html>